<?php
class SearchController extends Controller
{

    //Basic Search
    public  function  actionIndex()
    {
        $query=$_REQUEST["keyword"];



        $criteria=new CDbCriteria;
        $criteria->condition.=' TENSP like \'%'.$query.'%\'';

        //$criteria->order='MASP DESC';
        $postCount=Sanpham::model()->count($criteria);

        $pages=new CPagination($postCount);
        $pages->pageSize=6;
        $pages->applyLimit($criteria);

        $sanpham=SanPham::model()->findAll($criteria);

        $this->render('index',array(
            'model'=>$sanpham,
            'pages'=>$pages,
        ));
    }
    public  function  actionIndex1()
    {
        $query=$_REQUEST["keyword"];
        $f=$_REQUEST["from"];
        $t=$_REQUEST["to"];
        $criteria=new CDbCriteria;

        if($query == "TỪ KHÓA...")
            $query = "";

        if(is_numeric($f) && is_numeric($t))
            $criteria->condition.=' TENSP like \'%'.$query.'%\' and GIATIEN >= '.$f.' and GIATIEN <= '.$t.'';
        else
        {
            if(is_numeric($f))
                $criteria->condition.=' TENSP like \'%'.$query.'%\' and GIATIEN >= '.$f.'';
            else
            {
                if(is_numeric($t))
                    $criteria->condition.=' TENSP like \'%'.$query.'%\' and GIATIEN <= '.$t.'';
                else
                    $criteria->condition.=' TENSP like \'%'.$query.'%\'';
            }
        }

        //$criteria->order='MASP DESC';
        $postCount=Sanpham::model()->count($criteria);

        $pages=new CPagination($postCount);
        $pages->pageSize=6;
        $pages->applyLimit($criteria);

        $sanpham=SanPham::model()->findAll($criteria);

        $this->render('index',array(
            'model'=>$sanpham,
            'pages'=>$pages,
        ));
    }
    
    public  function  actionIndex2()
    {
        $query=$_REQUEST["keyword"];
        $f=$_REQUEST["from"];
        $t=$_REQUEST["to"];
        $criteria=new CDbCriteria;

        if($query == "TỪ KHÓA...")
            $query = "";

        if(is_numeric($f) && is_numeric($t))
            $criteria->condition.=' TENSP like \'%'.$query.'%\' and GIATIEN >= '.$f.' and GIATIEN <= '.$t.'';
        else
        {
            if(is_numeric($f))
                $criteria->condition.=' TENSP like \'%'.$query.'%\' and GIATIEN >= '.$f.'';
            else
            {
                if(is_numeric($t))
                    $criteria->condition.=' TENSP like \'%'.$query.'%\' and GIATIEN <= '.$t.'';
                else
                    $criteria->condition.=' TENSP like \'%'.$query.'%\'';
            }
        }

        //$criteria->order='MASP DESC';
        $postCount=Sanpham::model()->count($criteria);

        $pages=new CPagination($postCount);
        $pages->pageSize=6;
        $pages->applyLimit($criteria);

        $sanpham=SanPham::model()->findAll($criteria);

        $this->render('adminindex',array(
            'model'=>$sanpham,
            'pages'=>$pages,
        ));
    }
    
}
?>